package com.controller;


import com.entities.CommonResult;
import com.entities.Payment;
import com.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Description: 支付控制类
 *
 * @Autor: Rolin
 * datetime: 04-23-15:35
 */

@RestController
public class PaymentController {

    @Autowired
    PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/payment/insert")
//    注意，单一启动需要吧@RequestBody 注解去掉
    public CommonResult<Payment> create( @RequestBody Payment payment){
        int result = paymentService.insert(payment);
        if(result>0){
            return new CommonResult("执行成功,serverPort="+serverPort,200, payment);
        }else {
            return new CommonResult("执行失败",444,null);
        }
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult getById(@PathVariable("id")Integer id){
        Payment payment = paymentService.selectById(id);
        if (payment==null){
            return new CommonResult("执行失败",444,null);
        }else {
            return new CommonResult("执行成功,serverPort="+serverPort,200,payment);
        }
    }

    //    这里测试ribbon自定义轮询负载均衡算法
    @GetMapping("/payment/lb")
    public String testForRibbon(){
        //此处就返回个端口号用于测试
        return serverPort ;
    }

}
